package top.go2do.auth.business.permission.module;

import jakarta.persistence.*;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * @Description
 * @Author xingyj
 * @CreateTime 2025/5/15 15:01
 */
@Entity
@Table(name = "permission", uniqueConstraints = {
        @UniqueConstraint(name = "idx_unique_app_perm_code", columnNames ={"app_id", "perm_code"}),
        @UniqueConstraint(name = "idx_unique_app_perm_name", columnNames ={"app_id", "perm_name"})
})
@Data
public class PermissionPO {
    @Id
    @Column(name = "perm_id", columnDefinition = "BIGINT UNSIGNED COMMENT '权限ID(雪花算法分布式ID)'")
    private Long permId;

    @Column(name = "app_id", nullable = false, columnDefinition = "VARCHAR(32) COMMENT '所属应用ID'")
    private String appId;

    @Column(name = "perm_code", nullable = false, columnDefinition = "VARCHAR(100) COMMENT '权限编码（每个应用内唯一）'")
    private String permCode;

    @Column(name = "perm_name", nullable = false, columnDefinition = "VARCHAR(100) COMMENT '权限名称（每个应用内唯一）'")
    private String permName;

    @Column(name = "perm_type", nullable = false, columnDefinition = "TINYINT UNSIGNED COMMENT '类型：1=菜单,2=按钮,3=API'")
    private Integer permType;

    @Column(name = "created_at", nullable = false, insertable = false, updatable = false,
            columnDefinition = "DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) COMMENT '创建时间'")
    private LocalDateTime createdAt;

    @Column(name = "created_by", nullable = false,
            columnDefinition = "BIGINT UNSIGNED COMMENT '创建者'")
    private Long createdBy;

    @Column(name = "updated_at", nullable = false, insertable = false, updatable = false,
            columnDefinition = "DATETIME(6) DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6) COMMENT '更新时间'")
    private LocalDateTime updatedAt;

    @Column(name = "updated_by", nullable = false,
            columnDefinition = "BIGINT UNSIGNED COMMENT '更新者'")
    private Long updatedBy;
}
